// 回顶部
require(['jquery','easing'], function() {

	var offset = 200, isAnimate = false;
	var $back ;

	if ($(".back-to-top").length <= 0) {
		createBtn();
		$back = $('.back-to-top');
	}

	$(window).on('scroll', function() {

		var scrollTop = $(window).scrollTop();

		if (scrollTop >= offset) {
			showBackBtn();
		} else {
			hideBackBtn();
		}

	});

	$back.on('click', function(){
		if( !isAnimate ){
			isAnimate = true;
			$('html, body').animate({
				scrollTop : 0
			}, 300, 'easeOutSine', function(){
				isAnimate = false;
			});
		}
	});

	function showBackBtn() {
		$back.show();
	}

	function hideBackBtn() {
		$back.fadeOut();
	}

	function createBtn() {
		var $btnWrap = $('<div class="back-to-top"></div>');
		$('body').append($btnWrap);
	}
	
});